VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "TestDate"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Dim AdoCnn1 As New ADODB.Connection

Private Const CONST_ServerSZ As String = "10.53.6.170"
Private Const CONST_ServerXA As String = "10.53.60.6"
Private Const CONST_XiAnIP3s As String = "60,62"
Private mServer As String

Public Function Test_for_Quality(ENAID As String) As Boolean
    On Error GoTo ErrHandler:

    Dim cmd As New ADODB.Command
    If ENAID <> "" Then
        Set cmd.ActiveConnection = AdoCnn1
        cmd.CommandText = "Test_for_Quality"
        cmd.CommandType = adCmdStoredProc
        cmd.Parameters.Refresh
        cmd(1) = ENAID
        cmd(2).Direction = adParamOutput
        cmd.Execute
        
        If (cmd(2) = "1") Then
        Test_for_Quality = True
        Else
        Test_for_Quality = False
        End If
        
    'Else
    
    End If
    Exit Function
    
ErrHandler:
    Exit Function
    
End Function
'link test
Public Function Conn_test(userid As String, pwd As String) As Boolean
    Call Open_conn(userid, pwd)
    If AdoCnn1.state = adStateOpen Or AdoCnn1.state = adStateConnecting Then
        Conn_test = True
    Else
        Conn_test = False
        Exit Function
    End If
    Call Close_conn
End Function
'open
Public Sub Open_conn(userid As String, pwd As String)
    On Error GoTo ErrHandler:
    
    '2015.8.10 by zhangxianfeng (ShenZhen & XiAn Server)
    Dim cFty As New clsFactory
    mServer = IIf(cFty.IsXiAnIP(CONST_XiAnIP3s), CONST_ServerXA, CONST_ServerSZ)
    
    AdoCnn1.Provider = "sqloledb"
    AdoCnn1.Open "Data Source='" + mServer + "';user id=" + userid + ";password=" + pwd + ";Initial Catalog='ATE';Persist Security Info='False';"
ErrHandler:
    Exit Sub
End Sub


'close
Public Sub Close_conn()
    AdoCnn1.Close
    Set AdoCnn1 = Nothing
End Sub

'Private Function GetSimpleName(name As String) As String
'
'    Dim tempString() As String
'    tempString = Split(name, "&")
'    name = tempString(0)
'    tempString = Split(name, "#")
'    name = tempString(0)
'    tempString = Split(name, "_")
'    name = tempString(UBound(tempString))
'    GetSimpleName = name
'
'End Function

'check product id
Public Function Test_IsvaildPID(ProductTypeID As String, userid As String, pwd As String) As Boolean
    On Error GoTo ErrHandler:
    Call Open_conn(userid, pwd)
    Dim cmd As New ADODB.Command
    If ProductTypeID <> "" Then
        Set cmd.ActiveConnection = AdoCnn1
        cmd.CommandText = "Test_IsvaildPID"
        cmd.CommandType = adCmdStoredProc
        cmd.Parameters.Refresh
        cmd(1) = ProductTypeID
        cmd(2).Direction = adParamOutput
        cmd.Execute
        
        If (cmd(2) = "1") Then
        Test_IsvaildPID = True
        Else
        Test_IsvaildPID = False
        End If
    End If
    Call Close_conn
    '+++++++++++++++++++++++++++++++++++++++++++++++++
    'MsgBox "Test_IsvaildPID = " & Test_IsvaildPID
    '+++++++++++++++++++++++++++++++++++++++++++++++++
    Exit Function
    
ErrHandler:
    Call Close_conn
    Exit Function
    
End Function
'check product id for ANT
Public Function Test_IsvaildPID_ANT(ProductTypeID As String, userid As String, pwd As String) As Boolean
    On Error GoTo ErrHandler:
    Call Open_conn(userid, pwd)
    Dim cmd As New ADODB.Command
    If ProductTypeID <> "" Then
        Set cmd.ActiveConnection = AdoCnn1
        cmd.CommandText = "TTest_IsvaildPID"
        cmd.CommandType = adCmdStoredProc
        cmd.Parameters.Refresh
        cmd(1) = ProductTypeID
        cmd(2).Direction = adParamOutput
        cmd.Execute
        
        If (cmd(2) = "1") Then
        Test_IsvaildPID_ANT = True
        Else
        Test_IsvaildPID_ANT = False
        End If
    End If
    Call Close_conn
    Exit Function
    
ErrHandler:
    Call Close_conn
    Exit Function
    
End Function
'submit test
Public Function Test_HasDebugTest(productSN As String) As String
    On Error GoTo ErrHandler:

    Dim cmd As New ADODB.Command
    If productSN <> "" Then
        Set cmd.ActiveConnection = AdoCnn1
        cmd.CommandText = "Test_HasDebugTest"
        cmd.CommandType = adCmdStoredProc
        cmd.Parameters.Refresh
        cmd(1) = productSN
        cmd(2).Direction = adParamOutput
        cmd.Execute
        Test_HasDebugTest = cmd(2)
    
    End If
    Exit Function
    
ErrHandler:
    Exit Function
    
End Function
'ENA online
Public Function ENAOnline(ENAID As String, userid As String) As String
    On Error GoTo ErrHandler:
    
    Dim cmd As New ADODB.Command
    
    Set cmd.ActiveConnection = AdoCnn1
    cmd.CommandText = "ENA_Online"
    cmd.CommandType = adCmdStoredProc
    cmd.Parameters.Refresh
    cmd(1) = ENAID
    cmd(2) = userid
    cmd(3).Direction = adParamOutput
    cmd.Execute
    
    ENAOnline = cmd(3)
            
    Exit Function
    
ErrHandler:
    
End Function

Public Function Test_IsvaildClientSoftVersion(csname As String, csversion As String) As Boolean

    On Error GoTo ErrHandler:
    Dim cmd As New ADODB.Command
    If csname <> "" Then
        Set cmd.ActiveConnection = AdoCnn1
        cmd.CommandText = "Test_IsvaildClientSoftVersion"
        cmd.CommandType = adCmdStoredProc
        cmd.Parameters.Refresh
        cmd(1) = csname
        cmd(2) = csversion
        cmd(3).Direction = adParamOutput
        cmd.Execute
        
        If (cmd(3) = "1") Then
        Test_IsvaildClientSoftVersion = True
        Else
        Test_IsvaildClientSoftVersion = False
        End If
    End If
    '+++++++++++++++++++++++++++++++++++++++++++++++++
    'MsgBox "Test_IsvaildClientSoftVersion = " & Test_IsvaildClientSoftVersion
    '+++++++++++++++++++++++++++++++++++++++++++++++++
    Exit Function
    
ErrHandler:
    Exit Function
    
End Function
Public Function Read_ExcelAndWrite_Sql_Initial(ByRef sFile1 As ItemConf1) As Boolean
    On Error GoTo ErrHandler:
    
    Dim cmd As New ADODB.Command
    If sFile1.productSN <> "" Then
        Set cmd.ActiveConnection = AdoCnn1
        '2015-06-01 modifyed by zhangxianfeng for v3.9
        'cmd.CommandText = "Test_Insert_Initial"
        'cmd.CommandText = "Test_Insert_Initial_1"
        cmd.CommandText = "Test_Insert_Initial_2"
        cmd.CommandType = adCmdStoredProc
        cmd.Parameters.Refresh
        cmd(1) = sFile1.productSN
        cmd(2) = sFile1.ProductTypeID
        cmd(3) = sFile1.userid
        cmd(4) = sFile1.ENAID
        cmd(5) = sFile1.Switch
        cmd(6).Direction = adParamOutput
        cmd(7) = sFile1.IsDebugTest
        cmd(8) = sFile1.SpecVersion
        cmd(9) = sFile1.ATEVersion
        cmd.Execute
        
        If (cmd(6) = "1") Then
        Read_ExcelAndWrite_Sql_Initial = True
        Else
        Read_ExcelAndWrite_Sql_Initial = False
        End If
    
    End If
    
    '+++++++++++++++++++++++++++++++++++++++++++++++++
    'MsgBox "Read_ExcelAndWrite_Sql_Initial(IsDebugTest=" & sFile1.IsDebugTest & ") = " & Read_ExcelAndWrite_Sql_Initial
    '+++++++++++++++++++++++++++++++++++++++++++++++++
    Exit Function
    
ErrHandler:
    If AdoCnn1.state = adStateOpen Then
        AdoCnn1.Close
    End If
    Set AdoCnn1 = Nothing
    Set cmd = Nothing
End Function

Public Function Read_ExcelAndWrite_Sql(ByRef sFile1 As ItemConf1, ByRef sFile2() As ItemConf) As Boolean
    On Error GoTo ErrHandler:
    
    Dim StartTime
    StartTime = Now
    
    Dim i As Integer
    Dim strPsn As String
    Dim currtime
    Dim cmd As New ADODB.Command
    strPsn = sFile1.productSN
    
    Dim myLen As Integer
    If sFile1.KValue = 0 Then
        Read_ExcelAndWrite_Sql = True
        GoTo ErrHandler:
    End If
    If sFile1.IsFullTest = False Then
        myLen = sFile1.KValue - 1
        sFile1.Pass = "Fail"
    Else
        myLen = UBound(sFile2)
    End If
    If strPsn <> "" Then
        Set cmd.ActiveConnection = AdoCnn1
        '2015-11-02
        'cmd.CommandText = "Test_Insert"
        cmd.CommandText = "Test_Insert_with2DSN"
        cmd.CommandType = adCmdStoredProc
        cmd.Parameters.Refresh
        cmd(1) = sFile1.productSN
        cmd(2) = sFile1.ProductTypeID
        cmd(3) = sFile1.userid
        cmd(4) = sFile1.ENAID
        cmd(5) = sFile1.Pass
        cmd(6) = sFile1.Switch
        cmd(7) = sFile1.IsFullTest
        cmd(8).Direction = adParamOutput
        cmd(9).Direction = adParamOutput
        '2015-11-02
        cmd(10) = sFile1.TwoDimensionSN
        cmd.Execute
        currtime = cmd(8)
        strPsn = cmd(9)
        Set cmd.ActiveConnection = AdoCnn1
        cmd.CommandText = "TestItem_Insert"
        cmd.CommandType = adCmdStoredProc
        For i = LBound(sFile2) To myLen
            cmd.Parameters.Refresh
            cmd(1) = sFile2(i).ItemName
            cmd(2) = strPsn
            cmd(3) = sFile2(i).MeasType
            cmd(4) = sFile2(i).StartF
            cmd(5) = sFile2(i).StopF
            cmd(6) = sFile2(i).max
            cmd(7) = sFile2(i).min
            cmd(8) = sFile2(i).HighSpec
            cmd(9) = sFile2(i).LowSpec
            cmd(10) = sFile2(i).Pass
            cmd(11) = currtime
            cmd(12) = sFile2(i).TypeName
            cmd.Execute
        Next i
                
    Else
    End If
    
    If Asc(strPsn) = 0 Then
        Read_ExcelAndWrite_Sql = False
    Else
        Read_ExcelAndWrite_Sql = True
    End If
    
    '+++++++++++++++++++++++++++++++++++++++++++++++++
    'MsgBox "Read_ExcelAndWrite_Sql time(s) = " & Abs(DateDiff("s", Now, StartTime))
    '+++++++++++++++++++++++++++++++++++++++++++++++++
    Exit Function
    
ErrHandler:
    If AdoCnn1.state = adStateOpen Then
        AdoCnn1.Close
    End If
    Set AdoCnn1 = Nothing
    Set cmd = Nothing
    
End Function
'the main function for ANT
Public Function Read_ExcelAndWrite_Sql_ANT(ByRef sFile1 As ItemConf1, ByRef sFile2() As ItemConf) As Boolean
    
On Error GoTo ErrHandler:
    Dim i As Integer
    Dim strPsn As String
    Dim currtime
    Dim cmd As New ADODB.Command
    strPsn = sFile1.productSN
    Dim myLen As Integer
    If sFile1.KValue = 0 Then
        Read_ExcelAndWrite_Sql_ANT = True
        GoTo ErrHandler:
    End If
    If sFile1.IsFullTest = False Then
        myLen = sFile1.KValue - 1
        sFile1.Pass = "Fail"
    Else
        myLen = UBound(sFile2)
    End If
    If strPsn <> "" Then
        Set cmd.ActiveConnection = AdoCnn1
        cmd.CommandText = "TTest_Insert"
        cmd.CommandType = adCmdStoredProc
        cmd.Parameters.Refresh
        cmd(1) = sFile1.productSN
        cmd(2) = sFile1.ProductTypeID
        cmd(3) = sFile1.userid
        cmd(4) = sFile1.ENAID
        cmd(5) = sFile1.Pass
        cmd(6) = sFile1.Switch
        cmd(7).Direction = adParamOutput
        cmd(8).Direction = adParamOutput
        cmd.Execute
        currtime = cmd(7)
        strPsn = cmd(8)
        'MsgBox (LBound(sFile2))
        'MsgBox (UBound(sFile2))
        Set cmd.ActiveConnection = AdoCnn1
        cmd.CommandText = "TTestItem_Insert"
        cmd.CommandType = adCmdStoredProc
        For i = LBound(sFile2) To myLen
            cmd.Parameters.Refresh
            cmd(1) = sFile2(i).ItemName
            cmd(2) = strPsn
            cmd(3) = sFile2(i).MeasType
            cmd(4) = sFile2(i).StartF
            cmd(5) = sFile2(i).StopF
            cmd(6) = sFile2(i).max
            cmd(7) = sFile2(i).min
            cmd(8) = sFile2(i).HighSpec
            cmd(9) = sFile2(i).LowSpec
            cmd(10) = sFile2(i).Pass
            cmd(11) = currtime
            cmd(12) = sFile2(i).TypeName
            cmd.Execute
        Next i
    Else
    End If
    'temp = Asc(strPsn)
    If Asc(strPsn) = 0 Then
        Read_ExcelAndWrite_Sql_ANT = False
    Else
        Read_ExcelAndWrite_Sql_ANT = True
    End If
    'Exit Function
    
ErrHandler:
    If AdoCnn1.state = adStateOpen Then
        AdoCnn1.Close
    End If
    Set AdoCnn1 = Nothing
    Set cmd = Nothing
    
End Function

Public Function ProductType_Flow_HasValidPostStep(productSN As String, ProductTypeID As String, stepItem As String) As Boolean
    
    On Error GoTo ErrHandler:
    Dim cmd As New ADODB.Command
    If productSN <> "" Then
        Set cmd.ActiveConnection = AdoCnn1
        cmd.CommandText = "ProductType_Flow_HasValidPostStep"
        cmd.CommandType = adCmdStoredProc
        cmd.Parameters.Refresh
        cmd(1) = productSN
        cmd(2) = ProductTypeID
        cmd(3) = stepItem
        cmd(4).Direction = adParamOutput
        cmd.Execute
        
        If (cmd(4) = True) Then
            ProductType_Flow_HasValidPostStep = True
        Else
            ProductType_Flow_HasValidPostStep = False
        End If
    End If
    '+++++++++++++++++++++++++++++++++++++++++++++++++
    'MsgBox "ProductType_Flow_HasValidPostStep = " & ProductType_Flow_HasValidPostStep
    '+++++++++++++++++++++++++++++++++++++++++++++++++
    Exit Function
    
ErrHandler:
    ProductType_Flow_HasValidPostStep = False
    Exit Function
    
End Function
'2014-11-10
Public Function tb_IsvaildPID(ProductTypeID As String, ByVal userid As String, ByVal pwd As String) As Boolean
    
    On Error GoTo ErrHandler:
    tb_IsvaildPID = False
    Call Open_conn(userid, pwd)
    Dim cmd As New ADODB.Command
    If ProductTypeID <> "" Then
        Set cmd.ActiveConnection = AdoCnn1
        cmd.CommandText = "tb_IsProductType_ZTE"
        cmd.CommandType = adCmdStoredProc
        cmd.Parameters.Refresh
        cmd(1) = ProductTypeID
        cmd(2).Direction = adParamOutput
        cmd.Execute
        
        If (cmd(2) = "1") Then
            tb_IsvaildPID = True
        Else
            tb_IsvaildPID = False
        End If
    Else
    End If
    Call Close_conn
    '+++++++++++++++++++++++++++++++++++++++++++++++++
    'MsgBox "tb_IsvaildPID = " & tb_IsvaildPID
    '+++++++++++++++++++++++++++++++++++++++++++++++++
    Exit Function
    
ErrHandler:
    Call Close_conn
    Exit Function
    
End Function
'2014-11-10
Public Function Read_ExcelAndWrite_Sql1(ByRef sFile1 As tb_result_DFL, ByRef sFile2() As tb_Param_DFL, ProductTypeID As String) As Boolean
    
    On Error GoTo ErrHandler:
    
    Dim StartTime
    StartTime = Now
    
    Dim i As Integer
    Dim currentid
    Dim strPsn As String
    Dim cmd As New ADODB.Command
    strPsn = sFile1.partcode
    
    If strPsn <> "" Then
        Set cmd.ActiveConnection = AdoCnn1
        cmd.CommandText = "tb_result_DFL_Insert"
        cmd.CommandType = adCmdStoredProc
        cmd.Parameters.Refresh
        cmd(1).Direction = adParamOutput
        cmd(2) = strPsn
        cmd(3) = sFile1.testtime
        cmd(4) = sFile1.testperiod
        cmd(5) = sFile1.testequipid
        cmd(6) = sFile1.tfpid
        cmd(7) = sFile1.userid
        If (sFile1.totalresult = "Fail") Then
            cmd(8) = 1
        Else
            cmd(8) = 0
        End If
        cmd(9) = sFile1.itemresult
        cmd(10) = sFile1.itemselinfo
        cmd(11) = sFile1.itemselcnt
        cmd(12) = sFile1.itemcnt
        cmd(13) = sFile1.remark
        cmd(14).Direction = adParamOutput
        cmd.Execute
        currentid = cmd(1)
        strPsn = cmd(14)
        
            
        Set cmd.ActiveConnection = AdoCnn1
        cmd.CommandText = "tb_Param_DFL_Insert"
        cmd.CommandType = adCmdStoredProc
        For i = LBound(sFile2) To UBound(sFile2)
            cmd.Parameters.Refresh
            cmd(1) = currentid
            cmd(2) = strPsn
            cmd(3) = sFile2(i).testequipid
            cmd(4) = sFile2(i).UnitName
            cmd(5) = sFile2(i).testtime
            cmd(6) = sFile2(i).ParamName
            cmd(7) = sFile2(i).Res
            cmd(8) = sFile2(i).ResValue
            cmd(9) = sFile2(i).ResDesc
            cmd.Execute
        Next i
        
        Set cmd.ActiveConnection = AdoCnn1
        cmd.CommandText = "tb_DFL_Info_Insert"
        cmd.CommandType = adCmdStoredProc
        cmd.Parameters.Refresh
        cmd(1) = currentid
        cmd(2) = strPsn
        cmd(3) = sFile1.testtime
        cmd(4) = ProductTypeID
        cmd.Execute
                
    Else
    End If
    
    If Asc(strPsn) = 0 Then
        Read_ExcelAndWrite_Sql1 = False
    Else
        Read_ExcelAndWrite_Sql1 = True
    End If
    
    '+++++++++++++++++++++++++++++++++++++++++++++++++
    'MsgBox "Read_ExcelAndWrite_Sql1 time(s) = " & Abs(DateDiff("s", Now, StartTime))
    '+++++++++++++++++++++++++++++++++++++++++++++++++
    Exit Function
    
ErrHandler:
    If AdoCnn1.state = adStateOpen Then
        AdoCnn1.Close
    End If
    Set AdoCnn1 = Nothing
    Set cmd = Nothing
    
End Function

